package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.aop.ApiController;
import one.stand.enums.LoginEnum;
import one.stand.model.CompanyModel;
import one.stand.model.ResultModel;
import one.stand.request.SendSmsCodeRequest;
import one.stand.request.WxLoginRequest;
import one.stand.response.LoginResponse;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("crmPc/home")
@Api(tags="crm-PC基础接口")
public class HomeController extends BaseController {

    @RequestMapping("/getPcLoginImg")
    @ApiOperation(value = "微信扫码接口")
    @ApiController(isParam = false)
    public ResultModel<String> getPcLoginImg(HttpServletRequest httpServletRequest) {
        String companyKey=httpServletRequest.getHeader("companyKey");
        logger.info("请求companyKey:{}",companyKey);
        return loginFegin.getPcLoginImg(companyKey);
    }

    @PostMapping("/pcLoginCallBack")
    @ApiController(isParam = false)
    public ResultModel<LoginResponse> pcLoginCallBack(String code, String state){
        return loginFegin.pcLoginCallBack(code,state);
    }


    /**
     * 短信发送
     * @param request
     * @return
     */
    @ApiOperation(value = "验证码发送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号", required = true, paramType = "String"),
            @ApiImplicitParam(name = "type", value = "1登录验证", required = true, paramType = "Integer"),
    })
    @PostMapping("sendSms")
    @ApiController(paramClass = SendSmsCodeRequest.class )
    public ResultModel<Boolean> sendSms(@RequestAttribute SendSmsCodeRequest request){
        return loginFegin.sendSms(request);
    }

    /**
     * 短信登录
     * @param request
     * @return
     */
    @ApiOperation(value = "短信登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "companyId", value = "企业id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "smsCode", value = "验证码", required = true, paramType = "String"),
    })
    @PostMapping("crmPcLoginBySms")
    @ApiController(paramClass =WxLoginRequest.class )
    public ResultModel<LoginResponse> crmPcLoginBySms(@RequestAttribute WxLoginRequest request){
        return loginFegin.crmPcLoginBySms(request);
    }

    @ApiOperation(value = "根据手机号获取公司信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号", required = true, paramType = "Integer"),
    })
    @PostMapping("getCompanyListByPhone")
    @ApiController(paramClass =SendSmsCodeRequest.class )
    public ResultModel<List<CompanyModel>> getCompanyListByPhone(@RequestAttribute SendSmsCodeRequest request){
        return loginFegin.getCompanyListByPhone(request);
    }
}
